package com.it.spzx.controller;

import com.it.spzx.pojo.Order;
import com.it.spzx.pojo.User;
import com.it.spzx.service.UserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * projectName: springCloud
 *
 * @author: 王宝贵
 * time: 2024/9/13 19:46 周五
 * description:
 */

//@RestController
@Controller
@ResponseBody
@Slf4j
public class UserController
{

    @Value("${server.port}")
    private String port;

    @Resource
    private UserService userService ;

    @PostMapping(value = "/user/add")
    public boolean addUser(@RequestBody User user) {
        return userService.save(user);
    }

    @GetMapping(value = "/user/get/{userId}")
    public User findUserByUserId(@PathVariable(value = "userId") Long userId) {
        System.out.println("********User Module port: "+port);

        return userService.getById(userId) ;
    }

    /**
     * 用户微服务发起跨服务调用订单微服务，按照订单流水查询订单信息
     * http://localhost:10100/user/consumer/1
     * @param orderId
     * @return
     */
    //TODO 根据订单的id在用户模块调用了订单模块的方法
    @GetMapping(value = "/user/consumer/{orderId}")
    public Order getOrderByOrderId(@PathVariable("orderId") Long orderId)
    {
        return userService.getOrderByOrderId(orderId);
    }
}

